#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1.2e6 + 5;
const int A = 1e6;
int n, m;
int a[N], d[N], cnt[N];
vector<int> b;
int ans[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) d[a[i]]++;
  int mx = *max_element(a + 1, a + n + 1);
  per(i, mx, 1) {
    if (d[i]) {
      for (int j = 1; j * j <= i; j++) {
        if (i % j) continue;
        int k = i / j;
        cnt[j] += d[i];
        if (k != j) cnt[k] += d[i];
      }
    }
    if (cnt[i] >= m) {
      b.push_back(i);
    }
  }
  reverse(b.begin(), b.end());
  for (int x : b) {
    for (int i = x; i <= mx; i += x) ans[i] = max(ans[i], x);
  }
  rep(i, 1, n) cout << ans[a[i]] << endl;
  return 0;
}